<?

/**
* @property DB_active_record $db
* @property Base_flexmodel $base_flexmodel
* */
class Organisation_type extends Base_flexmodel { // CI_Model

	function __construct()
	{
		parent::__construct();
		$this->init('ics_ogranisation_type' , 'id' , 'name');
	}
	
//	function getProviderList ( )
//	{
//		return parent::get_where('pro_name');
//	}
	function getOrginsationName_byId( $id=null )
	{
		if ( $id == null || $id == '0' )
			return "All Organisations";
		$qq = parent::get_where ( array('id' => $id) );
		return $qq[0]->name != null ? $qq[0]->name : "" ;
	}

//	function getByRange($range, $type, $x, $y) {
//		if ($range == "" || !($x > 0 && $y > 0)) return false;
//		
//		$distsqbound = 1000000*$range*$range;		
//		$sql = "SELECT POW(datas.x-?,2)+POW(datas.y-?,2)";		
//		$sql .= "as distsq, datas.*, id.type_id ";
//		if ($type == '') $sql .= ", serv.name as service_name ";
//		$sql .= "from (ics_provider_data datas, ics_services_id id) ";
//		if ($type == '') $sql .= "LEFT JOIN ics_services as serv ON (id.type_id = serv.type_id) ";		
//		$sql .= "WHERE POW(datas.x-?,2)+POW(datas.y-?,2)  <= $distsqbound ";
//		if ($type != '' && strlen($type) > 16) $sql .= "AND id.type_id = ? ";
//
//		$sql .= "AND datas.pro_id = id.pro_id ";
//		$sql .= "ORDER by distsq ";
//		$this->writeLog($sql);
//		$q = ($type != '' && strlen($type) > 16) ? $this->db->query($sql,array($x,$y,$x,$y,$type)) : $this->db->query($sql,array($x,$y,$x,$y));
//		if ($q->num_rows() > 0) {
//			return $q->result();
//		}
//		return false;
//	}
	
//	function getByType($type, $x, $y) {
//		if ($type == "" || !($x > 0 && $y > 0)) return false;
//		$sql = "SELECT serv.name, datas.pro_id, datas.pro_name, datas.x, datas.y, datas.postal, "
//		. " POW(datas.x-?,2)+POW(datas.y-?,2) as distsq "
//		. "	from (ics_services serv, ics_provider_data datas, ics_services_id id) "
//		. " INNER JOIN ( select DISTINCT pro_id from ics_zone where type_id = ? ) Z on datas.pro_id = Z.pro_id "
//		. " where serv.type_id=id.type_id AND datas.pro_id = id.pro_id "
//		. " AND serv.is_zone = 'Y'"
//		. " AND serv.type_id = ?"
//		. " ORDER BY distsq ASC";
//		//. " AND serv.is_zone = 'Y' AND datas.is_zone = 'Y' "		
//		$q = $this->db->query($sql,array($x,$y,$type,$type));
//		if ($q->num_rows() > 0) {
//			return $q->result();
//		}
//		return false;		
//	}
//	
//	function getZone($service, $provNo) {
//		if ($service == "" && $provNo == "") return false;
//		$zTable = "gis_lyr_ics_".trim(strtolower($service));
//		if ($this->db->table_exists($zTable)) {
//			$sql = "select g.OBJECT_VECTOR zone from `$zTable` g, ics_zone z
//			LEFT JOIN ics_provider_data `data` ON (data.pro_id = z.pro_id)
//			where z.type_id = ? AND g.OBJECT_ID = z.object_id AND ";
//			if (is_numeric($provNo)) $sql .= "data.no = ?";
//			else $sql .= "z.pro_id = ?";
//			
//			$q = $this->db->query($sql,array($service,$provNo));
//			
//			if ($q->num_rows() > 0) {
//				return $q->result();
//			}
//		}
//		return false;		
//	}

}

//class Provider
//{
//	public $no;
//	public $pro_id;
//	public $is_zone; 
//	public $zone;
//	public $pro_name;
//	public $block;
//	public $street; 
//	public $building; 
//	public $unit; 
//	public $postal; 
//	public $telp; 
//	public $fax; 
//	public $X;
//	public $Y;
//
//	public function Provider( ) {}
//	public function Provider( $no , $pro_id , $is_zone ,  $zone , 
//		$pro_name , $block , $street , $building , 
//		$unit , $postal , $telp , $fax , $X , $Y
//	)
//	{
//		$this->$no = $no;
//		$this->$pro_id = $pro_id;
//		$this->$is_zone = $is_zone;
//		$this->$zone = $zone;
//		$this->$pro_name = $pro_name;
//		$this->$block = $block;
//		$this->$street = $street;
//		$this->$building = $building;
//		$this->$unit = $unit;
//		$this->$postal = $postal;
//		$this->$telp = $telp;
//		$this->$fax = $fax;
//		$this->$X = $X;
//		$this->$Y = $Y;
//	}
//
//}
